package com.gzx.plugin.tjzy.modular.trace.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzx.plugin.tjzy.modular.trace.bo.GzxTracePlanAddBo;
import com.gzx.plugin.tjzy.modular.trace.bo.GzxTracePlanQueryBo;
import com.gzx.plugin.tjzy.modular.trace.service.GzxTracePlanService;
import com.gzx.plugin.tjzy.modular.trace.vo.GzxTracePlanVo;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;

/**
 * 跟进计划通知 gzx_trace_plan
 *
 * @author xbl
 * &#064;date  2025-03-28
 */
@Slf4j
@RestController
@RequestMapping("/tjzy/trace")
@RequiredArgsConstructor
public class GzxTracePlanController {

    private final GzxTracePlanService tracePlanService;

    /**
     * 跟进计划通知分页
     */
    @PostMapping("/pageTracePlan")
    public CommonResult<Page<GzxTracePlanVo>> pageFoundsFlow(@RequestBody GzxTracePlanQueryBo tracePlanQueryBo) {
        try {
            return CommonResult.data(tracePlanService.page(tracePlanQueryBo));
        } catch (Exception e) {
            log.error("跟进计划通知分页异常： {0} ", e);
            return CommonResult.error("跟进计划通知分页 未知错误，请联系管理员");
        }
    }

    /**
     * 添加跟进计划通知
     */
    @DS("sms")
    @Operation(summary = "添加跟进计划通知")
    @CommonLog("添加跟进计划通知")
    @PostMapping("/addTracePlan")
    public CommonResult<String> addTracePlan(@RequestBody GzxTracePlanAddBo tracePlanAddBo) {
        tracePlanService.add(tracePlanAddBo);
        return CommonResult.ok();
    }

    /**
     * 编辑跟进计划通知
     */
    @DS("sms")
    @Operation(summary = "编辑跟进计划通知")
    @CommonLog("编辑跟进计划通知")
    @PostMapping("/editTracePlan")
    public CommonResult<String> edit(@RequestBody GzxTracePlanAddBo tracePlanAddBo) {
        tracePlanService.edit(tracePlanAddBo);
        return CommonResult.ok();
    }

    /**
     * 删除跟进计划通知
     */
    @DS("sms")
    @Operation(summary = "删除跟进计划通知")
    @CommonLog("删除跟进计划通知")
    @GetMapping("/deleteTracePlan/{id}")
    public CommonResult<String> deleteTracePlan(@PathVariable Long id) {
        tracePlanService.del(id);
        return CommonResult.ok();
    }

}
